<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/9/24
  Time: 13:48
  To change this template use File | Settings | File Templates.
--%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:if test="${requestScope.count==0}">
  <script>
    alert("添加失败")
  </script>
</c:if>
<c:if test="${requestScope.count>0}">
  <script>
    alert("添加成功")
  </script>
</c:if>
<html>
  <head>
    <title>$Title$</title>
  </head>
  <body>
  请输入查询关键字:<input type="text" name="cname" id="tj"> <button id="btn">搜索</button> <a href="add">添加常见问题</a>
  <table id="firstTr">
    <tr >
      <td>编号</td>
      <td>标题</td>
      <td>创建时间</td>
      <td>分类</td>
    </tr>
  </table>
  <span id="sp"></span>
  </body>
<script src="js/jquery-1.9.1.min.js"></script>
<script>
  $(function () {
    bindFaqs();
    bindch();
    binEvnd()
  })

  function formartDate(obj){
    var d = new Date();
    d.setTime(obj);
    var str = d.getFullYear()+"-"+(d.getMonth()+1)+"-"+d.getDate();
    return str;
  }
  function bindFaqs() {
    var cname = $("#tj").val();
    $.post("list",{"cname":cname},function (msg) {
    var str=""
    $(msg).each(function (i) {
      var f=msg[i]
        str += "<tr>"
        str += "<td>" + f.id + "</td>"
        str += "<td><a href='getselect?id=" + f.id +"'>" + f.title + "<a></td>"
        str += "<td>" + formartDate(f.createDate) + "</td>"
        str += "<td>" + f.classes.cname + "</td>"
        str += "</tr>"

    })
      $("#firstTr tr:not(:first)").remove();
      $("#firstTr").append(str);
    },"json")
  }
  function bindch() {
    $("#btn").click(function () {
      bindFaqs()
    })
  }

</script>
</html>
